package com.ty.zls.listener;

import android.content.Context;

import com.aspsine.swipetoloadlayout.OnLoadMoreListener;
import com.aspsine.swipetoloadlayout.SwipeToLoadLayout;
import com.qmuiteam.qmui.widget.QMUIEmptyView;
import com.ty.zls.adapter.ArreageAdapter;
import com.ty.zls.adapter.CheckWaterAdapter;
import com.ty.zls.task.ArreageTask;
import com.ty.zls.task.CheckWaterTask;
import com.ty.zls.util.StrogeUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * 抄表刷新listener
 */
public class WaterCheckLoadMoreListener implements OnLoadMoreListener {

    private CheckWaterAdapter adapter;
    private Context context;
    private SwipeToLoadLayout layout;
    private Map<String, String> request = new HashMap<>();
    private QMUIEmptyView emptyView;
    private String search = "";

    public void setSearch(String search) {
        this.search = search;
    }

    public WaterCheckLoadMoreListener(CheckWaterAdapter adapter, Context context, SwipeToLoadLayout swipeToLoadLayout, QMUIEmptyView emptyView) {
        this.adapter = adapter;
        this.context = context;
        this.layout = swipeToLoadLayout;
        this.emptyView = emptyView;
    }

    @Override
    public void onLoadMore() {
        String token = StrogeUtil.getStringFraomPs(context, StrogeUtil.user, StrogeUtil.token);
        request.put("token", token);
        request.put("search",search);
        request.put("pageNum", String.valueOf(adapter.getPageNum()));
        request.put("pageSize", String.valueOf(adapter.getPageSize()));
        new CheckWaterTask(emptyView, context,adapter,layout).execute(request);
        layout.setLoadingMore(false);
    }

    public void autoRefresh() {
        layout.post(new Runnable() {
            @Override
            public void run() {
                layout.setRefreshing(true);
            }
        });
    }



}
